/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-10-17 下午9:37 Created by lyyang
 */
package com.xunton.bss.weixin.api.button;

import java.util.HashMap;
import javax.inject.Named;

import com.jade.framework.base.util.HttpUtils;
import com.xunton.bss.weixin.api.Response;


/**
 * 微信自定义菜单代理
 *
 * @author <a href="mailto:lyyang@ceno.cn">lyyang</a>
 * @version 1.0 15-10-17 下午9:37
 */
@Named ("weixin_buttonAgent")
public class ButtonAgent
{
    private String createUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=";

    public void create(String token,Button[] buttons) throws Exception{
        HashMap<String,Button[]> param = new HashMap<String, Button[]>();
        param.put("button",buttons);
        Response response = HttpUtils.postJsonHttp(createUrl+token,param, Response.class);
        if (!response.isOK()){
            throw new Exception(response.getErrorMsg());
        }
    }
}
